using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Wips.Domain.Models.Authorities.Model
{
    /// <summary>
    /// 职位
    /// </summary>
    [Table("AuthorityPositions")]
    [SugarTable("AuthorityPositions")]
    public class Position : EntityBase, IAggregateRoot
    {

        /// <summary>
        /// 上级
        /// </summary>
        public string ParentId { get; set; }

        /// <summary>
        /// 上级路径，用逗号分割，用于快速检索
        /// </summary>
        public string ParentPath { get; set; }

        /// <summary>
        /// 名称
        /// </summary>
        [Required]
        [MaxLength(32)]
        public string Name { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remarks { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public Status Status { get; set; }


        /// <summary>
        /// 最后更新人Id
        /// </summary>
        public string LastUpdatedUserId { get; set; }

        /// <summary>
        /// 最后更新人
        /// </summary>

        [Navigate(NavigateType.ManyToOne, nameof(LastUpdatedUserId))]
        public User LastUpdatedUser { get; set; }


        /// <summary>
        /// 状态变更
        /// </summary>
        /// <param name="lastUpdatedUserId"></param>
        public void StatusChange(string lastUpdatedUserId)
        {
            Status = Status == Status.Disabled ? Status.Enabled : Status.Disabled;
            LastUpdatedUserId = lastUpdatedUserId;
            Updated = DateTime.Now;
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="parentId"></param>
        /// <param name="parentPath"></param>
        /// <param name="name"></param>
        /// <param name="remarks"></param>
        /// <param name="userId"></param>
        public void Update(string parentId, string parentPath, string name, string remarks, string userId)
        {
            ParentId = parentId;
            ParentPath = parentPath;
            Name = name;
            Remarks = remarks;
        }
    }
}